package com.example.demo.YmlController;

import com.example.demo.YmlController.List2020;
import com.example.demo.YmlController.MapTypes;
import com.example.demo.YmlController.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
//@RequestMapping("/p1")
public class PropertiesController {
    @Value("${m.k}")
    private String k;

    @RequestMapping("/v1")
    public String key(){//参数名 input 与成员变量 k 同名,否则可能会读取失败
        System.out.println("注入后的key值为: " + k);
        if (k == null) {
            System.out.println("key的值为null");
        }
        return "读取到properties文件中的mykey1的值: "+ k;
    }

    @Value("${code.java}")
    private String java;
    @RequestMapping("/v2")
    public String v2(){
        return "读取yml配置文件code.java的值: "+ java;
    }

    @Value("${String.str1}")
    private String str1;
    @Value("${String.str2}")
    private String str2;
    @Value("${String.str3}")
    private String str3;

    @RequestMapping("/v3")
    public String v3(){
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
        return "yml";
    }

    @Autowired
    private Student student;
    @RequestMapping("/v4")
    public String v4(){
        return student.toString();
    }

    @Autowired
    private List2020 list2020;

    @RequestMapping("/v5")
    public String v5(){
        return list2020.toString();
    }

    @Autowired
    private MapTypes mapTypes;

    @RequestMapping("/v6")
    public String v6(){
        return mapTypes.toString();
    }

}
